package com.ibm.risk.irmp.base.auth.dao;

import com.ibm.risk.irmp.base.auth.entity.SystemBizBranch;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface BizBranchRepository extends JpaRepository<SystemBizBranch, String> {
    Page<SystemBizBranch> findByBranchNameContainingIgnoreCase(String branchName, Pageable pageable);

    @Query(nativeQuery = true, value = "select * from ri_base_auth_biz_branch where parent_code is null and is_active")
    List<SystemBizBranch> findActiveHeadOrgs();

    @Query("select b.children from SystemBizBranch b where b.branchCode = ?1 and b.isActive = ?2")
    List<SystemBizBranch> findByParentCode(String parentCode, Boolean isActive);
}
